﻿using System;
using System.Collections.Generic;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class ExternOleDdeLink: ExternNameStructure
    {
        private ShortXLUnicodeString linkName;
        public string LinkName { get { return (string) linkName; } }
        private uint lStgName;
        private MOper moper;

        public override void Read(BinaryReader reader)
        {
            throw new NotSupportedException();
        }
        public void Read (BinaryReader reader, int length)
        {
            this.lStgName = reader.ReadUInt32();
            this.linkName = new ShortXLUnicodeString();
            this.linkName.Read(reader);
            int remainingSize = length - 6 - linkName.ByteLength;
            if (remainingSize > 0)
            {
                this.moper = new MOper();
                this.moper.Read(reader);
            }
        }

        public override void Write(BinaryWriter writer)
        {
            throw new NotImplementedException();
        }

        public override string Name
        {
            get { return (string) this.linkName; }
        }
    }

    internal class MOper
    {
        private byte colLast;
        private ushort rowLast;
        private List<SerAr> extOper;

        public void Read(BinaryReader reader)
        {
            colLast = reader.ReadByte();
            this.rowLast = reader.ReadUInt16();
            extOper = new List<SerAr>();
            int count = (colLast + 1)*(rowLast + 1);
            for (int i = 0; i < count; i++)
                extOper.Add(SerAr.Read(reader));
        }
    }
}